package com.androidx.p013lv.mine.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Process;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.lzy.okgo.model.Progress;

/* renamed from: com.androidx.lv.mine.dialog.DialogUpdate */
public class DialogUpdate extends Dialog {
    private TextView btnConfirm;
    private String content;
    private long exitTime;
    private ImageView imageView;
    private boolean isForceUpdate;
    private LinearLayout llClose;
    private String mUrl;
    private ProgressBar progressBar;
    private TextView progressTxt;
    private TextView textView;
    private TextView textViewTitle;
    private String title;
    private VersionUpdateInterface versionUpdateInterface;

    /* renamed from: com.androidx.lv.mine.dialog.DialogUpdate$VersionUpdateInterface */
    public interface VersionUpdateInterface {
        void dismissDialog();

        void onConfirmClick();
    }

    public DialogUpdate(Context context, String str, String str2, String str3, boolean z, VersionUpdateInterface versionUpdateInterface2) {
        super(context, C1207R.C1214style.ForceUpdateAppDialog);
        setContentView(C1207R.C1212layout.dialog_version_update_layout);
        this.mUrl = str3;
        this.title = str;
        this.content = str2;
        this.isForceUpdate = z;
        this.versionUpdateInterface = versionUpdateInterface2;
        Window window = getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.gravity = 17;
        window.setAttributes(attributes);
        if (this.isForceUpdate) {
            setCancelable(false);
            setCanceledOnTouchOutside(false);
        } else {
            setCancelable(true);
            setCanceledOnTouchOutside(true);
        }
        this.imageView = (ImageView) findViewById(C1207R.C1210id.dialog_version_update_close);
        this.llClose = (LinearLayout) findViewById(C1207R.C1210id.ll_close);
        this.imageView.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.dialog.DialogUpdate.View$OnClickListenerC12931 */

            public void onClick(View view) {
                DialogUpdate.this.dismiss();
            }
        });
        this.textViewTitle = (TextView) findViewById(C1207R.C1210id.dialog_version_update_title);
        this.textView = (TextView) findViewById(C1207R.C1210id.dialog_version_update_content);
        this.progressBar = (ProgressBar) findViewById(C1207R.C1210id.version_update_progress_bar);
        this.progressTxt = (TextView) findViewById(C1207R.C1210id.version_update_progress_txt);
        TextView textView2 = (TextView) findViewById(C1207R.C1210id.dialog_version_update_confirm_btn);
        this.btnConfirm = textView2;
        textView2.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.dialog.DialogUpdate.View$OnClickListenerC12942 */

            public void onClick(View view) {
                if (TextUtils.isEmpty(DialogUpdate.this.mUrl)) {
                    DialogUpdate.this.isForceUpdate();
                    ToastUtils.getInstance().showWeak("無效下載鏈接");
                } else if (DialogUpdate.this.mUrl.startsWith("http")) {
                    try {
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        intent.setData(Uri.parse(DialogUpdate.this.mUrl));
                        DialogUpdate.this.getContext().startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    DialogUpdate.this.isForceUpdate();
                } else {
                    DialogUpdate.this.isForceUpdate();
                    ToastUtils.getInstance().showWeak("下載鏈接非法");
                }
            }
        });
        initData();
        setOnDismissListener(new DialogInterface.OnDismissListener() {
            /* class com.androidx.p013lv.mine.dialog.DialogUpdate.DialogInterface$OnDismissListenerC12953 */

            public void onDismiss(DialogInterface dialogInterface) {
                if (!DialogUpdate.this.isForceUpdate && DialogUpdate.this.versionUpdateInterface != null) {
                    DialogUpdate.this.versionUpdateInterface.dismissDialog();
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void isForceUpdate() {
        if (this.isForceUpdate) {
            Process.killProcess(Process.myPid());
            System.exit(1);
            return;
        }
        dismiss();
    }

    private void initData() {
        if (TextUtils.isEmpty(this.content)) {
            dismiss();
            return;
        }
        this.textView.setText(this.content);
        if (TextUtils.isEmpty(this.title)) {
            dismiss();
            return;
        }
        this.textViewTitle.setText(this.title);
        if (this.isForceUpdate) {
            this.llClose.setVisibility(8);
        } else {
            this.llClose.setVisibility(0);
        }
    }

    public void onBackPressed() {
        if (this.isForceUpdate) {
            onBackPressedBtn();
        } else {
            super.onBackPressed();
        }
    }

    public void startDownLoad() {
        this.llClose.setVisibility(8);
        this.btnConfirm.setVisibility(8);
        this.progressTxt.setVisibility(0);
        this.progressBar.setVisibility(0);
    }

    public void setProgressState(Progress progress) {
        double d = (double) progress.currentSize;
        Double.isNaN(d);
        double d2 = (double) progress.totalSize;
        Double.isNaN(d2);
        int i = (int) (((d * 1.0d) / (d2 * 1.0d)) * 100.0d);
        this.progressBar.setProgress(i);
        TextView textView2 = this.progressTxt;
        textView2.setText(String.valueOf(i + "%"));
    }

    private void onBackPressedBtn() {
        if (System.currentTimeMillis() - this.exitTime > 1000) {
            this.exitTime = System.currentTimeMillis();
        } else if (getContext() != null) {
            ((Activity) getContext()).finish();
        }
    }
}
